//
//  M13XMLParser.m
//  ELife
//
//  Created by feng lu on 11-5-13.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "M13XMLParser.h"


@implementation M13XMLParser
@synthesize xmlData;


-(void) XMLDataParser:(NSData*)iData target:(id<M13XMLParserDelegate>)target
{
    delegate = target;
    xmlData = [NSData dataWithData:iData];
    NSXMLParser *parser = [[NSXMLParser alloc] initWithData:xmlData];
    parser.delegate = self;
    
    currentString = [NSMutableString string];
    [parser parse];
    [parser release];
}


- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *) qualifiedName attributes:(NSDictionary *)attributeDict {
    for (int i = 0; i<[parserWord count] ; i++) {
        if([elementName isEqualToString:[parserWord objectAtIndex:i]])
        {
            [currentString setString:@""];
            storingCharacters = YES;
        }
    }
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
    for (int i = 0; i<[parserWord count] ; i++) {
        if([elementName isEqualToString:[parserWord objectAtIndex:i]])
        {
            [delegate parser:currentString];
        }
    }
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
    if (storingCharacters) [currentString appendString:string];
}

/*
 A production application should include robust error handling as part of its parsing implementation.
 The specifics of how errors are handled depends on the application.
 */
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError {
    // Handle errors as appropriate for your application.
}


- (void)dealloc
{
    [currentString release];
    [parserWord release];
    [xmlData release];
}
@end
